'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class Snac0110
    Inherits Snac

    Public Sub New()
        MyBase.New(&H1, &H10)
    End Sub

    Private _NewWarningLevel As Integer
    Public Property NewWarningLevel() As Integer
        Get
            Return _NewWarningLevel
        End Get
        Set(ByVal value As Integer)
            _NewWarningLevel = value
        End Set
    End Property

    Private _UserInfos As New List(Of UserInfo)
    Public ReadOnly Property UserInfos() As List(Of UserInfo)
        Get
            Return _UserInfos
        End Get
    End Property

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = Snac.SizeFixPart
        
        _NewWarningLevel = ByteConverter.ToUInt16(data.GetRange(index, 2))
        index += 2

        Do While index < data.Count
            Dim info As UserInfo

            info = New UserInfo
            index += info.Deserialize(index, data)

            UserInfos.Add(info)
        Loop

        SetTotalSize(index)
    End Sub

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Throw New NotImplementedException
    End Function

    Public Overrides Function CalculateDataSize() As Integer
        Dim size As Integer = 2
        For Each x As UserInfo In UserInfos
            size += x.CalculateTotalSize
        Next
        Return size
    End Function
End Class

Public Class TlvOnlineTime
    Inherits Tlv

    Public Sub New()
        MyBase.New(&HF)
    End Sub

    Private _OnlineTime As DateTime
    Public Property OnlineTime() As DateTime
        Get
            Return _OnlineTime
        End Get
        Set(ByVal value As DateTime)
            _OnlineTime = value
        End Set
    End Property

    Public Overrides Function Serialize() As System.Collections.Generic.List(Of Byte)
        Dim data As List(Of Byte) = MyBase.Serialize()

        data.AddRange(ByteConverter.GetBytesForUInt32Date(_OnlineTime))

        Return data
    End Function

    Public Overrides Sub Deserialize(ByVal data As System.Collections.Generic.List(Of Byte))
        MyBase.Deserialize(data)

        Dim index As Integer = Tlv.SizeFixPart

        _OnlineTime = ByteConverter.ToDateTimeFromUInt32FileStamp(data.GetRange(index, 4))
    End Sub

    Public Overrides Function CalculateDataSize() As Integer
        Return 4
    End Function
End Class